package com.fandou.airobot.data.repository;

import androidx.lifecycle.MutableLiveData;

import com.blankj.utilcode.util.SPUtils;
import com.fandou.airobot.R;
import com.fandou.airobot.data.bean.HomeItem;
import com.fandou.airobot.data.config.Configs;
import com.fandou.airobot.database.Record;
import com.fandou.airobot.database.RecordDatabase;

import java.util.ArrayList;
import java.util.List;

public class DataRepository implements ILocalSource, IRemoteSource {

    @Override
    public void getHomePageItems(MutableLiveData<List<HomeItem>> liveData) {
        List<HomeItem> homeItems = new ArrayList<HomeItem>() {{
            add(new HomeItem("记录模式", R.mipmap.icon_camera,
                    R.drawable.ai_robot_selector_home_page_item_camera,
                    R.id.action_homeFragment_to_recordingFragment));
            add(new HomeItem("拍照搜题", R.mipmap.icon_search, R.drawable.ai_robot_selector_home_page_item_search, R.id.action_aiRobotHomeFragment_to_aiRobotPaitiFragment));
            add(new HomeItem("设置闹钟", R.mipmap.icon_clock, R.drawable.ai_robot_selector_home_page_item_clock, R.id.action_aiRobotHomeFragment_to_aiRobotAlarmListFragment));
        }};

        liveData.setValue(homeItems);
    }

    @Override
    public void getRecordingPeriodTime(MutableLiveData<Integer> liveData) {
        liveData.setValue(SPUtils.getInstance().getInt(Configs.RECORDING_PERIOD, 5));
    }

    @Override
    public void saveRecordingPeriodTime(int time) {
        SPUtils.getInstance().put(Configs.RECORDING_PERIOD, time);
    }

    @Override
    public void getRecordHistoryList(MutableLiveData<List<Record>> liveData) {
        List<Record> records = RecordDatabase.getInstance().recordDao().getAllRecords();
        liveData.setValue(records);
    }

    private final static class Singleton {
        private final static DataRepository instance = new DataRepository();
    }

    private DataRepository() {
    }

    public static DataRepository getInstance() {
        return Singleton.instance;
    }
}
